package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ebook.entity.Ebook;
import cn.ebook.service.dao.impl.EbookServiceImpl;
import cn.ebook.util.GsonUtil;
import cn.ebook.util.VoUtil;
import cn.ebook.vo.WebVo;

public class getwillsetServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		//获取参数
		String bookidstr=request.getParameter("bookid");
		//校验参数
		if("".equals(bookidstr)|null==bookidstr){
			//出错了
			System.out.println("错误");
		}
		Long ebookId=new Long(bookidstr);
		//调用service返回结果
		EbookServiceImpl b=new EbookServiceImpl();
		Ebook e=b.findEbookByid(ebookId);
		//处理结果
		WebVo vo=null;
		if(e==null){
			vo=VoUtil.getErro(null);
		}else{
			vo=VoUtil.getSuccess(e);
		}
		//把结果封装为json
		System.out.println(vo);
		String json=GsonUtil.getJson(vo);
		out.write(json);
		out.flush();
		out.close();
	}

	

}
